<route lang="json5">
{
  style: {
    navigationBarTitleText: '员工添加/编辑',
  },
}
</route>
<template>
    <item width="180rpx" title="员工名称" required>
        <wd-input v-model="obj.title" clearable />
    </item>

    <item width="180rpx" title="类型" required>
        <wd-radio-group v-model="obj.type" shape="dot" inline>
            <wd-radio value="线上">线上</wd-radio>
            <wd-radio value="到店核销">到店核销</wd-radio>
        </wd-radio-group>
    </item>

    <item width="180rpx" title="主图" required tips="最多上传5张图片，参考尺寸：750*750">
        <upload v-model="obj.images" num="5" />
    </item>

    <item width="180rpx" title="物流信息" tips="例：甘肃、新疆﹑西藏、海南﹑港典台不发货﹔国内其他地区包邮!广东省发货，每天下午4点发货">
        <wd-textarea v-model="obj.logistics" clearable auto-height :maxlength="255" />
    </item>

    <item width="180rpx" title="是否有规格" required>
        <wd-radio-group v-model="obj.has_spec" shape="dot" inline>
            <wd-radio value="是">是</wd-radio>
            <wd-radio value="否">否</wd-radio>
        </wd-radio-group>
    </item>

    <item width="180rpx" title="规格" required v-if="obj.has_spec == '是'" @click="spec_show = true">

    </item>

    <template v-else>
        <item width="180rpx" title="价格" required>
            <wd-input-number v-model="obj.price" :precision="2" :min="0.1" input-width="140rpx" />
        </item>

        <item width="180rpx" title="原价">
            <wd-input-number v-model="obj.original_price" :precision="2" :min="0" allow-null input-width="140rpx" />
        </item>

        <item width="180rpx" title="库存" required>
            <wd-input-number v-model="obj.stock" :precision="0" :min="1" input-width="140rpx" />
        </item>
    </template>

    <item width="180rpx" title="详情">
    </item>

    <bottom_button title="提交" :fixed="false" class="submit" @click="submit()" />

    <spec v-model="obj.spec" v-model:show="spec_show" />
</template>

<script lang="ts" setup>
import { useStore } from '@/utils/store';
import spec from './spec.vue';

const store = useStore()
const spec_show = ref(false)
const obj = ref({
    id: 0,
    title: '',
    store_id: store.store.id,
    type: '线上',
    images: [],
    logistics: '',
    price: 1,
    original_price: '',
    stock: 0,
    detail: '',
    has_spec: '否',
    spec: [],
})

function submit() {
    let param = JSON.parse(JSON.stringify(obj.value))
    if (param.original_price === '') param.original_price = null
}
</script>

<style scoped></style>